perm filename FINAL.XGP[S77,JMC] blob
sn#322594 filedate 1977-12-14 generic text, type T, neo UTF8
/LMAR=0/XLINE=3/FONT#0=BAXL30/FONT#1=BAXM30/FONT#2=BAXB30/FONT#3=SUB/FONT#4=SUP/FONT#5=BASL35/FONT#6=NGR25/FONT#7=MATH30/FONT#8=FIX25/FONT#9=GRK30
␈↓ ↓H␈↓CS206␈↓ ¬_FINAL EXAMINATION␈↓
SPRING 1977
␈↓ ↓H␈↓␈↓ α_This␈α
examination␈α
is␈α
open␈α
book␈α
and␈α∞notes.␈α
Write␈α
LISP␈α
functions␈α
as␈α
follows␈α∞except␈α
where
␈↓ ↓H␈↓something else is requested. Either notation may be used.
␈↓ ↓H␈↓1.␈α
␈↓↓alt1␈α
u␈↓␈αcontains␈α
alternate␈α
elements␈αof␈α
the␈α
list␈α
␈↓↓u␈↓␈αin␈α
the␈α
same␈αorder␈α
as␈α
in␈α␈↓↓u␈↓␈α
ending␈α
with␈α
the␈αlast
␈↓ ↓H␈↓element of ␈↓↓u␈↓. Thus
␈↓ ↓H␈↓␈↓ α_␈↓↓alt1␈↓ (A B) = (B),
␈↓ ↓H␈↓␈↓ α_␈↓↓alt1␈↓ (A B C) = (A C),
␈↓ ↓H␈↓and
␈↓ ↓H␈↓␈↓ α_␈↓↓alt1␈↓ (A B C D) = (B D).
␈↓ ↓H␈↓2. ␈↓↓iscompact x␈↓, where ␈↓↓x␈↓ is a list structure, is true if all EQUAL substructures in ␈↓↓x␈↓ are EQ.
␈↓ ↓H␈↓3.␈α∂␈↓↓partitions␈α∂n␈↓␈α∂is␈α∂a␈α∂list␈α∂of␈α∂the␈α⊂partitions␈α∂of␈α∂the␈α∂integer␈α∂␈↓↓n␈↓␈α∂into␈α∂sums␈α∂of␈α∂smaller␈α⊂integers.␈α∂ Thus
␈↓ ↓H␈↓␈↓↓partitions 1 = ((1)),␈α∞partitions 2 = ((2) (1 1)),␈α∞partitions␈α∞3␈α∞=␈α∞((3) (2 1) (1 1 1)),␈α∂and␈α∞partitions 4 =
␈↓ ↓H␈↓↓((4) (3 1) (2 2) (2 1 1) (1 1 1 1))␈↓.
␈↓ ↓H␈↓4. Define
␈↓ ↓H␈↓␈↓ α_␈↓↓length u ← ␈↓αif␈↓↓ ␈↓αn␈↓↓ u ␈↓αthen␈↓↓ 0 ␈↓αelse␈↓↓ 1 + length ␈↓αd␈↓↓ u␈↓,
␈↓ ↓H␈↓and as usual
␈↓ ↓H␈↓␈↓ α_␈↓↓u*v ← ␈↓αif␈↓↓ ␈↓αn␈↓↓ u ␈↓αthen␈↓↓ v ␈↓αelse␈↓↓ ␈↓αa␈↓↓ u . [␈↓αd␈↓↓ u * v]␈↓.
␈↓ ↓H␈↓Prove that
␈↓ ↓H␈↓␈↓ α_␈↓↓∀u v.(length[u*v] = length u + length v)␈↓.
␈↓ ↓H␈↓In␈αthe␈αproof␈αyou␈αmay␈αuse␈αany␈αfacts␈α
you␈αlike␈αabout␈αthe␈αproperties␈αof␈αaddition,␈αbut␈αyou␈α
must␈αstate
␈↓ ↓H␈↓what facts you are using.
␈↓ ↓H␈↓5.␈α∂Let␈α⊂␈↓↓e␈↓␈α∂be␈α∂a␈α⊂LISP␈α∂expression␈α⊂formed␈α∂from␈α∂numbers␈α⊂and␈α∂atoms␈α∂using␈α⊂PLUS␈α∂and␈α⊂TIMES␈α∂to
␈↓ ↓H␈↓represent␈α∪addition␈α∪and␈α∩multiplication.␈α∪ ␈↓↓polyprint e␈↓␈α∪is␈α∩a␈α∪list␈α∪of␈α∩the␈α∪characters␈α∪occurring␈α∪in␈α∩a
␈↓ ↓H␈↓printout of ␈↓↓e␈↓ in algebraic notation containing no unnecessary parentheses. Thus
␈↓ ↓H␈↓␈↓ α_␈↓↓polyprint␈↓ (TIMES (PLUS X (TIMES U V W)) X Z) = (LP X PLUS U V W RP X Z)
␈↓ ↓H␈↓which corresponds to the algebraic expression (X + UVW)XZ
␈↓ ↓H␈↓6.␈α⊂What␈α⊂code␈α∂will␈α⊂LCOM4␈α⊂generate␈α⊂from␈α∂(DEFUN␈α⊂FF␈α⊂(X)␈α⊂(COND␈α∂((ATOM␈α⊂X)␈α⊂X)␈α⊂(T␈α∂(FF
␈↓ ↓H␈↓(CAR X)))))?